#{extends 'main.html' /}
<div class="page-group">
    <div class="page page-current" id="user-userInfo">
        <header class="bar bar-nav">
            <a href="javascript:history.go(-1);" class="icon icon-left pull-left"></a>
            <h1 class="title">业主信息</h1>
        </header>
        <section class="user_info content scroll_y">
            <div class="list-block">
                <ul>
                    <li>
                        <div class="item-content">
                            <div class="item-inner">
                                <div class="item-title label">真实姓名</div>
                                <div class="item-input">
                                    <input type="text" id="realName" placeholder="请录入真实姓名"/>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-inner">
                                <div class="item-title label">手机号</div>
                                <div class="item-input">
                                    <input type="text" id="phone" placeholder="请录入手机号"/>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-inner">
                                <div class="item-title label">身份证号</div>
                                <div class="item-input">
                                    <input type="text" id="idCard" placeholder="请录入身份证号"/>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-inner">
                                <div class="item-title label">性别</div>
                                <div class="item-input">
                                    <select id="gender">
                                        <option value="MALE" selected>男</option>
                                        <option value="FEMALE">女</option>
                                        <option value="UNKNOWN">未知</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-inner">
                                <div class="item-title label">年龄</div>
                                <div class="item-input">
                                    <input type="text" id="age" placeholder="请录入年龄"/>
                                </div>
                            </div>
                        </div>
                    </li>
                </ul>
                <div class="content-block">
                    <input type="button" name="button" class="button button-fill button-big button-orange"
                           id="user-button" value="提交信息">
                </div>
            </div>
        </section>
    #{include 'weixin/footer.html'/}
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $.showPreloader();
        $.getJSON("/user/getUser", null,
            function (data) {
                $.hidePreloader();
                $("#realName").val(data.realName);
                $("#phone").val(data.phone);
                $("#idCard").val(data.idCard);
                $("#gender").val(data.gender);
                $("#age").val(data.age);
            }
        )
        $(document).off("click", "#user-button").on("click", "#user-button", function () {
            if($("#age").val() != "" && isNaN(parseInt($("#age").val()))){
                $.toast("年龄只能是数字");
                return;
            }
            $.showPreloader();
            $.getJSON("/user/saveUser", {
                        realName: $("#realName").val(),
                        phone: $("#phone").val(),
                        idCard: $("#idCard").val(),
                        gender: $("#gender").val(),
                        age: $("#age").val()
                    },
                    function (data) {
                        $.hidePreloader();
                        if (data.success) {
                            $.router.back();
                        } else {
                            $.toast(data.msg);
                        }
                    }
            )
        });
    });
    $.init();
</script>
